<include file="Public/header"/>

<div id="app">
    <!-- sidebar -->
    <include file="Public/left"/>
    <!-- / sidebar -->
    <div class="app-content">
        <!-- start: TOP NAVBAR -->
        <include file="Public/headernav"/>
        <!-- end: TOP NAVBAR -->
        <div class="main-content">
            <div class="wrap-content container" id="container" >
                <!-- start: PAGE TITLE -->
                <section id="page-title">
                    <div class="row">
                        <div>
                            <h1 class="mainTitle">文章管理</h1>
                            <span class="mainDescription">{$msgtitle}</span>
                        </div>
                    </div>
                </section>
                <!-- end: PAGE TITLE -->
                <!-- start: YOUR CONTENT HERE -->
                <!-- Start 平台文章发布-->
                <div class="container-fluid container-fullw bg-white" id="own_plat">
                    <form action="" role="form" id="form2" novalidate="novalidate" method="post">
                        <div class="col-md-10 ">
                            <div class="form-group">
                                <label class="control-label">
                                    标题 <span class="symbol required" aria-required="true"></span>
                                </label>
                                <input type="text" name="title" placeholder="请填写标题" value="{$data.title}" class="form-control"/>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    标题图<span class="symbol required" aria-required="true"></span>
                                </label>
                                <br>
                                <div class="upload_file">
                                    <label>
                                        <input type="file" name="head_photo" class="upload_input" id="head_photo"
                                               value="" style="display:none;">

                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                            <div class="fileinput-new thumbnail" id="show_photo">
                                                <img id="head_photo_src" src="{:U('wap/index/get_thumbs',array('auto'=>300))}?img={$data.img}" alt="">
                                            </div>
                                        </div>
                                        点击图片上传
                                    </label>
                                </div>
                                <input type="hidden" name="img" id="img" value="{$data.img}">
                            </div>
                                    <div class="form-group">
                                        <label class="control-label">
                                            审核状态
                                        </label>
                                        <div class="clip-radio radio-primary fa-hover Primary">
                                                <input type="radio" value="1" name="is_check" id="is_check_yes" {$data['is_check']?'checked':''}>
                                                <label for="is_check_yes">
                                                    已审核
                                                </label>
                                                <input type="radio" value="0" name="is_check" id="is_check_no" {$data['is_check']?'':'checked'}>
                                                <label for="is_check_no">
                                                    未审核
                                                </label>
                                        </div>
                                    </div>
                                <div class="form-group" id="show_goods_yes" style="display:none;">
                                    <label class="control-label">
                                        文章类型
                                    </label>
                                    <select class="form-control" id="brand_id" name="type">
                                        <option value="0" {$data['type']?'':'selected'}>普通文章</option>
                                        <option value="1" {$data['type']?'selected':''}>活动文章</option>
                                    </select>
                                </div>
                                <if condition="!empty($_GET['id']) and $data['type'] eq 1">
                                    <div class="form-group show_goods_no">
                                        <label class="control-label">
                                            活动商品 <span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <input type="button" value="选择活动产品"
                                               class="btn btn-primary" onclick="setGoods()" style="margin-bottom:10px; " />
                                        <div class="fileinput-new thumbnail">
                                            <img src="{:U('wap/index/get_thumbs',array('auto'=>300))}?img={$data.goods_img}" alt="" id="goods_img" />
                                        </div>
                                        <input type="hidden" name="goods_id" id="goods" value="{$data.goods_id}">
                                    </div>
                                    <div class="form-group show_goods_no">
                                        <label class="control-label">
                                            商品数量 <span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <input type="text" name="goods_num" placeholder="请输入商品数量"
                                               value="{$data.goods_num}"
                                               class="form-control"/>
                                    </div>
                                </if>
                                <!--<div class="form-group">-->
                                <!--<label class="control-label">-->
                                    <!--关联推文 <span class="symbol required" aria-required="true"></span>-->
                                <!--</label>-->
                                <!--<input type="text" name="tui_article" id="tui_article" placeholder="关联推文" value="{$data.tui_article}" class="form-control" readonly/>-->
                            <!--</div>-->
                            <!--<div class="form-group">-->
                                <!--<label class="control-label">-->
                                    <!--关联商品 <span class="symbol required" aria-required="true"></span>-->
                                <!--</label>-->
                                <!--<input type="text" name="tui_goods" id="value" placeholder="关联商品" value="{$data.tui_goods}"-->
                                       <!--class="form-control" readonly/>-->
                            <!--</div>-->
                            <div class="form-group">
                                <label class="control-label">
                                    内容 <span class="symbol required" aria-required="true"></span>
                                </label>
                                <textarea id="content" name="content" class="autosize" data-autosize-on="true" style="overflow: hidden; resize: horizontal; word-wrap: break-word; width:100%; height:800px;">{$data.content}</textarea>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-primary btn-wide pull-left" type="submit">
                                    提交 <i class="fa fa-arrow-circle-right"></i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- End 平台文章发布-->
                <!-- end: YOUR CONTENT HERE -->
            </div>
        </div>
    </div>
    <!--  FOOTER and SETTINGS -->

    <include file="Public/footer"/>
    <!-- end: FOOTER -->
    <!-- start: OFF-SIDEBAR -->

    <!-- end: OFF-SIDEBAR -->

</div>
<!-- start: MAIN JAVASCRIPTS -->

<include file="Public/javascript"/>

<!-- end: CLIP-TWO JAVASCRIPTS -->

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<script src="__PUBLIC__/bootstrap/vendor/ckeditor/adapters/jquery.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/jquery-validation/jquery.validate.min.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/ajaxfileupload/ajaxfileupload.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('content');
</script>
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<!-- start: CLIP-TWO JAVASCRIPTS -->
<!-- <script src="__PUBLIC__/bootstrap/assets/js/main.js"></script> -->
<!-- start: JavaScript Event Handlers for this page -->
<!--<script src="__PUBLIC__/bootstrap/assets/js/form-validation.js"></script>-->

<!-- end: JavaScript Event Handlers for this page -->
</body>
<script type="text/javascript">
    $().ready(function () {
        //表单验证
        $("#form2").validate({
            rules: {
                title: "required",
                content: "required",
                img:"required",
                goods_id:'required',
                goods_num:{
                    required:true,
                    range:[1,9999]
                }

            },
            messages: {
                title: '请输入文章标题',
                content: '请输入文章内容',
                img:"请上传标题图",
                goods_id:'请选择活动商品',
                goods_num:{
                    required:'请输入产品数量',
                    range:'产品数量介于1-9999之间'
                }
            }
        })
    })
    //活动弹窗
    $('[name="type"]').change(function(){
        var type=$('[name="type"]').val();
        $('.show_goods_no').remove();
        if(type==1){
            var content='<div class="form-group show_goods_no">'+
                    '<label class="control-label">'+
                    '活动商品 <span class="symbol required" aria-required="true"></span>'+
                    '</label>'+
                    '<input type="button" value="选择活动产品" class="btn btn-primary" onclick="setGoods()" style="margin-bottom:10px; "/>'+
                    '<div class="fileinput-new thumbnail">'+
                    '<img src="{:U(\'wap/index/get_thumbs\',array(\'auto\'=>300))} alt="" id="goods_img" />'+
                    '</div>'+
                    '<input type="hidden" name="goods_id" id="goods" value="">'+
                    '</div>'+
                    '<div class="form-group show_goods_no">'+
                    '<label class="control-label">'+
                    '商品数量 <span class="symbol required" aria-required="true"></span>'+
                    '</label>'+
                    '<input type="text" name="goods_num" placeholder="请输入商品数量"class="form-control"/>'+
                    '</div>';
            $('#show_goods_yes').after(content);
        }
    })
    //关联文章弹窗
    $('[name="tui_article"]').click(function () {
        var id='<?php echo $_GET["id"] ?>'
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            fix: false, //不固定
            maxmin: true,
            content: '{:U("admin/Usernotice/popup_tweet_list")}?id='+id
        });
    });
    //关联商品弹窗
    $('#value').click(function () {
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            fix: false, //不固定
            maxmin: true,
            content: '{:U("/admin/ad/popup_type")}?type=1'
        });
    })
    $(document).ready(function (e) {
        ///上传商家logo
        $('.upload_file').on('change', '.upload_input', function () {
            ajaxFileUploadview('head_photo', 'goods_image', "{:U('admin/Imagecat/upload_ajax')}");

        });

        $('.goods_image_url').on('click', '.delete_img', function () {
            if (confirm('您确定删除该图片？')) {
                $(this).parents('.fileinput').remove();
            }
        });

    });
    //文件上传带预览
    function ajaxFileUploadview(imgid, hiddenid, url) {

        $.ajaxFileUpload({
            url: url,
            secureuri: false,
            fileElementId: imgid,
            dataType: 'json',
            data: {name: 'logan', id: 'id'},
            success: function (data, status) {

                if (typeof (data.error) != 'undefined') {

                    if (data.error != '') {
                        var dialog = art.dialog({title: false, fixed: true, padding: 0});
                        dialog.time(2).content("<div class='tips'>" + data.error + "</div>");
                    } else {

                        var resp = data.msg;
                        if (resp != '0000') {
                            var dialog = art.dialog({title: false, fixed: true, padding: 0});
                            dialog.time(2).content("<div class='tips'>" + data.error + "</div>");
                            return false;
                        } else {
                            $('#head_photo_src').attr('src', data.imgurl);
                            $('#img').val(data.imgurl);

                            /* art.dialog.open("{:U('admin/Imagecat/index')}?img=" + data.imgurl, {
                             title: '裁剪图片',
                             width: '800px',
                             height: '400px'
                             });*/

                            //dialog.time(3).content("<div class='msg-all-succeed'>上传成功！</div>");
                        }
                    }
                }
            },
            error: function (data, status, e) {
                var dialog = art.dialog({title: false, fixed: true, padding: 0});
                dialog.time(3).content("<div class='tips'>" + e + "</div>");
            }
        })

        return false;
    }
    //活动商品
    function setGoods(){
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            fix: false, //不固定
            maxmin: true,
            content: '{:U("/admin/Draw/popup")}'
        });
    }
</script>
</html>
